home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / trap13.arc / SSFIX.ASM < prev    next >
Assembly Source File  |  1988-04-09  |  6KB  |  206 lines

  1. name    Td
  2. page    63,110
  3.  
  4. CODE    segment
  5.         assume  CS:CODE
  6.  
  7. Td      proc    near
  8.         org     100h                ; .COM file
  9.  
  10. start:  jmp     instal              ; to install code
  11.  
  12. savint: dd      ?                   ; save old int13 addr
  13.  
  14. doing:  db      ?                   ; routine execute status
  15.  
  16. save:    dw    6 dup(?)
  17.  
  18. saveCS   dw    ?
  19. saveIP   dw    ?
  20.  
  21. ourst:   db    24 dup('stack   ')
  22.  
  23. estack:  db    0
  24. ostseg:  dw    ?
  25. ostofs:  dw    ?
  26.  
  27. tdsig    dw    7777h
  28.          dw    8888h
  29.          dw    9999h
  30.          dw    0aaaah
  31.          dw    0deadh
  32.  
  33. tdres   proc  near
  34.  
  35.         push  ax
  36.  
  37.         push  bp                           ; get caller's address
  38.         mov   bp,sp
  39.         mov   ax,word ptr [bp+4]
  40.         mov   word ptr [saveIP], ax
  41.         mov   ax, word ptr [bp+6]
  42.         mov   word ptr [saveCS], ax
  43.         pop   bp
  44.  
  45.         push  ds
  46.         pushf
  47.  
  48.         push  cs
  49.         pop   ds
  50.  
  51.         cmp   byte ptr [doing],00h  ; can we execute?
  52.         jz    tdgk                  ; sure!
  53.         jmp   tdext                 ; int13 in progress, exit
  54.  
  55. tdgk:   mov   byte ptr [doing],0ffh    ; in progress marker
  56.  
  57.         mov   word ptr [save],ax       ; keep caller's stuff
  58.         mov   word ptr [save+4],cx     ;
  59.         pushf
  60.         pop   ax
  61.         mov   word ptr [save+10],ax
  62.  
  63.         cli
  64.         mov   ax,ss
  65.         mov   ostseg,ax
  66.         mov   ostofs,sp                ; save his stack, use ours
  67.         mov   ax,ds
  68.         mov   ss,ax
  69.         mov   sp,offset estack
  70.         sti
  71.  
  72.         mov   ax,word ptr[save]        ; get his stuff again
  73.         mov   cx,word ptr[save+4]
  74.  
  75.  
  76.         cmp   ch,27h                   ; test for SS sector read
  77.         jnz   doint
  78.         cmp   cl,02h
  79.         jz    fake
  80.         cmp   cl,06h
  81.         jnz   doint
  82.  
  83. fake:   mov   ax,1000h                 ; fake the error that SS likes
  84.         mov   word ptr[save],ax
  85.         mov   ax,word ptr [save+10]    ; get flags
  86.         or    ax,1                     ; set carry
  87.         mov   word ptr[save+10],ax
  88.         jmp   fakex
  89.  
  90. doint:  pushf
  91.         call dword ptr [savint]     ; simulate an OLD int
  92.  
  93.         mov  word ptr [save], ax    ; OLD int's result regs
  94.  
  95.         mov  word ptr [save+4],cx
  96.  
  97. fakex:  cli                         ; restore stack
  98.         mov   ax,ostseg
  99.         mov   ss,ax
  100.         mov   sp,ostofs
  101.         sti
  102.  
  103. tdext:  popf                           ; caller's local stuff
  104.         pop   ds
  105.         pop   ax
  106.  
  107.         pop   ax                        ; junk caller's ip
  108.         pop   ax                        ; junk his CS
  109.         pop   ax                        ; finally his flags
  110.         pushf                           ; give him OURS
  111.         mov   ax, word ptr[saveCS]      ; and his CS back
  112.         push  ax
  113.         mov   ax, word ptr[saveIP]      ; and his IP
  114.         push  ax
  115.  
  116.         mov   ax,word ptr [save+10]     ; our flags (to be safe)
  117.         push  ax
  118.         popf
  119.  
  120.         mov   ax, word ptr[save]        ; result in AX
  121.  
  122.         mov   byte ptr [doing],00h      ; no more execute
  123.  
  124. tdend:  iret                            ; adios!
  125.  
  126. tdall:  nop                              ; "offset + 1" of res
  127. tdres   endp
  128.  
  129. tdlen   equ     tdend-tdres         ; routine length
  130. siglen  equ     tdres-tdsig         ; check length
  131.  
  132. intoff  equ     (13h*4)+0             ; addr of tick vector
  133. intseg  equ     (13h*4)+2             ;
  134.  
  135. instal: push    ds                  ; save DOS return word
  136.         xor     ax,ax               ; clear out ax
  137.         push    ax                  ; for return
  138.         push    ax                  ; and to zero ES
  139.         pop     es
  140.         mov     ax,es:[intoff]      ; get 13h vector offset
  141.         push    ax                  ; move into di
  142.         pop     di                  ;
  143.         sub     di,siglen           ; point to where sig should be
  144.         mov     ax,es:[intseg]      ; get 13h vector seg
  145.         push    ax                  ; move into es
  146.         pop     es                  ;
  147.         mov     si,offset tdsig     ; get our routine's address
  148.         cld                         ; forward compare
  149.         mov     cx,siglen           ; length of routine
  150.  
  151. rescmp: cmps    ds:byte ptr[si],es:[di] ; loop while Z
  152.         loopz   rescmp
  153.  
  154.         jz      reserr              ; if all equal, already res.
  155.  
  156.         xor     ax,ax               ; segment 0000
  157.         push    ax
  158.         pop     es
  159.         mov     ax,word ptr es:[intoff]      ; get bios vector offset
  160.         mov     bx,offset savint
  161.         mov     word ptr [bx],ax      ; store 13h routine's offset
  162.  
  163.         mov     ax,word ptr es:[intseg]      ; get 13h routine's segment
  164.         inc     bx
  165.         inc     bx
  166.         mov     word ptr [bx],ax             ; store
  167.  
  168.         mov     byte ptr [doing], 0ffh          ; fake executing
  169.  
  170.         cli                         ; no interrupts while
  171.  
  172.         mov     word ptr es:[intoff], offset tdres  ;  storing
  173.         mov     word ptr es:[intseg], cs            ;  vectors
  174.  
  175.         sti                         ; interrupts Again
  176.  
  177.         mov     dx,offset resmsg    ; good msg
  178.         mov     ah,9                ; output string
  179.         int     21h                 ; display
  180.  
  181.         mov     doing, 00h          ; allow executing
  182.  
  183.         mov     dx,tdall            ; our resident portion
  184.         int     27h                 ; terminate & stay resident
  185.  
  186. reserr: mov     dx,offset errmsg    ; error msg
  187.         mov     ah,9                ; output string
  188.         int     21h                 ; display
  189.  
  190.         int     20h                 ; go home
  191.  
  192. Td      endp
  193.  
  194. resmsg: db      'SSFIX - Screen Sculptor Protection Fix'
  195.         db      ' - (c) 1985 Eric Pederson'
  196.         db      0dh
  197.         db      0ah
  198.         db      'Resident portion loaded'
  199.         db      '$'
  200.  
  201. errmsg: db      'SSFIX - Already resident'
  202.         db      '$'
  203.  
  204. CODE    ends
  205.         end     start
  206.